﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace UpdatedHomeMaker
{
    [Serializable]
    public class ServicingList
    {
        private List<ClientInfo> clients;

        public ServicingList()
        {
            clients = new List<ClientInfo>();
        }

        static public void SerializeToXML(ServicingList toSave)
        {
            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\HomeMaker\"))
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\HomeMaker\");
            XmlSerializer serializer = new XmlSerializer(typeof(ServicingList));
            TextWriter textWriter = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\HomeMaker\Info.xml");
            serializer.Serialize(textWriter, toSave);
            textWriter.Close();
        }
        static public ServicingList DeserializeFromXML()
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(ServicingList));
            TextReader textReader = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\HomeMaker\Info.xml");
            ServicingList loading;
            loading = (ServicingList)deserializer.Deserialize(textReader);
            textReader.Close();

            return loading;
        }
        
        public List<ClientInfo> Clients
        {
            get { return clients; }
            set { clients = value; }
        }
    }
    public enum PayStatus
    {
        [XmlEnum(Name = "paidFor")]
        paidFor,
        [XmlEnum(Name = "submitted")]
        submitted,
        [XmlEnum(Name = "notSubmitted")]
        notSubmitted
    }

    public class ClientInfo
    {
        private string firstName;
        private string middleName;
        private string lastName;
        private double totalUnits;
        private double usedUnits;
        private string ID;

        public List<DocumentedGroup> groupInfo;
        public ClientInfo()
        {
            firstName = "";
            middleName = "";
            lastName = "";
            totalUnits = 0;
            usedUnits = 0;
            ID ="0";
            groupInfo = new List<DocumentedGroup>();
        }
        public ClientInfo(ClientInfo toCopy)
        {
            firstName = toCopy.firstName;
            middleName = toCopy.middleName;
            lastName = toCopy.lastName;
            totalUnits = toCopy.totalUnits;
            usedUnits = toCopy.usedUnits;
            ID = toCopy.ID;
            groupInfo = new List<DocumentedGroup>(toCopy.groupInfo);
        }
        public override string ToString()
        {
            return firstName + " " + middleName + " " + lastName;
        }
        #region Get/Sets
        public string ID1
        {
            get { return ID; }
            set { ID = value; }
        }

        public string FirstName
        {
            get { return firstName; }
            set { firstName = value; }
        }
        
        public string MiddleName
        {
            get { return middleName; }
            set { middleName = value; }
        }

        public string LastName
        {
            get { return lastName; }
            set { lastName = value; }
        }

        public double TotalUnits
        {
            get { return totalUnits; }
            set { totalUnits = value; }
        }

        public double UsedUnits
        {
            get { return usedUnits; }
            set { usedUnits = value; }
        }
        #endregion
    }

    public class DocumentedGroup
    {
        public List<DocumentedDay> daysInGroup;
        private string groupingName;
        private double totalUnits;

        public DocumentedGroup()
        {
            daysInGroup = new List<DocumentedDay>();
            groupingName = "";
        }
        public DocumentedGroup(string name)
        {
            daysInGroup = new List<DocumentedDay>();
            groupingName = name;
        }
        public string GroupingName
        {
            get { return groupingName; }
            set { groupingName = value; }
        }
        public override string ToString()
        {
            return groupingName;
        }

        public double TotalUnits
        {
            get { return totalUnits; }
            set { totalUnits = value; }
        }
    }

    public class DocumentedDay
    {
        private PayStatus status;
        private string hoursAndMin;
        private DateTime startTime;
        private DateTime endTime;
        private int hours;
        private int min;
        private int units;

        public DocumentedDay()
        {
            status = PayStatus.notSubmitted;
            hoursAndMin = "0";
            startTime = DateTime.Now;
            endTime = DateTime.Now;
            hours = 0;
            min = 0;
            units = 0;
        }

        public DocumentedDay(DocumentedDay toEdit)
        {
            status = toEdit.status;
            hoursAndMin = toEdit.hoursAndMin;
            startTime = toEdit.startTime;
            endTime = toEdit.endTime;
            hours = toEdit.hours;
            min = toEdit.min;
            units = toEdit.units;
        }
        #region Gets/Sets

        public PayStatus Status
        {
            get { return status; }
            set { status = value; }
        }

        public DateTime StartTime
        {
            get { return startTime; }
            set { startTime = value; }
        }

        public DateTime EndTime
        {
            get { return endTime; }
            set { endTime = value; }
        }

        public int Hours
        {
            get { return hours; }
            set { hours = value; }
        }

        public int Min
        {
            get { return min; }
            set { min = value; }
        }

        public int Units
        {
            get { return units; }
            set { units = value; }
        }

        public string HoursAndMin
        {
            get { return hoursAndMin; }
            set { hoursAndMin = value; }
        }
        #endregion
    }
}
